package be.redo.model.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * @author Frank
 * 
 */
@Entity
@NamedQueries({
		@NamedQuery(name = "findAantalAirports", query = "select count(a) from Airport a"),
		@NamedQuery(name = "findAllAirports", query = "select a from Airport a order by a.name"),
		@NamedQuery(name = "findAirportsByNameLike", query = "select a from Airport a where a.name like( :name ) order by a.name"),
		@NamedQuery(name = "findAirportsByCodeLike", query = "select a from Airport a where a.code like( :code ) order by a.code"),
		@NamedQuery(name = "findAirportsByRegion", query = "select a from Airport a where a.region =  :region order by a.name"),
		@NamedQuery(name = "findAirportsByCodeEquals", query = "select a from Airport a where a.code =  :code ") })
public class Airport implements Serializable {

	/**
	 * Generated serialVersionUID
	 */
	private static final long serialVersionUID = -6818923816543842453L;

	/**
	 * Name of the airport.
	 */
	@NotNull
	@Size(min = 1, max = 255)
	private String name;

	/**
	 * Three character [A-Z] IATA code of the airport.
	 */
	@NotNull
	@Pattern(regexp = "[A-Z]{3}")
	private String code;

	/**
	 * Region of the airport.
	 */
	@NotNull
	@ManyToOne
	@JoinColumn(name = "region")
	private Region region;

	// /**
	// * Set of Lines with this airport as destination.
	// */
	// @NotNull
	// @OneToMany(cascade = CascadeType.ALL, mappedBy = "destination")
	// private Set<Line> arivals = new HashSet<Line>();
	//
	// /**
	// * Set of Lines departing from this airport.
	// */
	// @NotNull
	// @OneToMany(cascade = CascadeType.ALL, mappedBy = "departure")
	// private Set<Line> departures = new HashSet<Line>();

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Region getRegion() {
		return this.region;
	}

	public void setRegion(Region region) {
		this.region = region;
	}

	// public Set<Line> getArivals() {
	// return this.arivals;
	// }

	// public void setArivals(Set<Line> arivals) {
	// this.arivals = arivals;
	// }

	// public Set<Line> getDepartures() {
	// return this.departures;
	// }

	// public void setDepartures(Set<Line> departures) {
	// this.departures = departures;
	// }

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

	/**
	 * Generated key by the Database
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "airport_id")
	private Long AirportId;

	public Long getAirportId() {
		return this.AirportId;
	}

	public void setAirportId(Long id) {
		this.AirportId = id;
	}

}
